home *** CD-ROM | disk | FTP | other *** search
/ Learn Microsoft Visual Basic 6.0 Now / Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO / media / chap04 / b04d010.cc2 < prev    next >
Text File  |  1998-06-07  |  2KB  |  45 lines

  1. 0, In this demonstration you'll see how 
  2. 2, Visual Basic handles mathematical 
  3. 4, calculations with advanced operators. The program 
  4. 7, I've created is an advanced operator 
  5. 9, tester that uses two variable text boxes, 
  6. 13, a collection of Option buttons, and a 
  7. 15, Calculate button to compute a result. The 
  8. 18, program is running now and to 
  9. 20, demonstrate it, I'll type a 9 in the first text 
  10. 22, box and a 2 in the second text box. Then, 
  11. 29, I'll click the Integer Division button 
  12. 32, and click the Calculate button to display 
  13. 34, the result. Visual Basic displays a 4 
  14. 38, because 9/2=4. Remember in integer 
  15. 42, division, the remainder of 1 is discarded. 
  16. 47, When I click the Remainder button and click 
  17. 49, Calculate, I do see my remainder of 1. 
  18. 53, And if I click the Exponentiation button 
  19. 56, and click Calculate, I get 81, the 
  20. 58, product of 9 squared. Finally, using String 
  21. 62, Concatenation, I get a result of 92, the 
  22. 67, textural result of 9 added to 2. Now, 
  23. 73, let's look at the program code that 
  24. 75, controls these calculations. I'll stop the 
  25. 78, program and double-click the Calculate 
  26. 81, button to open the Command1_Click event 
  27. 84, procedure. In the event procedure, I 
  28. 87, declare the first and second variant variables 
  29. 90, to hold the numbers in the two text 
  30. 92, boxes. These were the 9 and 2 numbers in 
  31. 96, the example I just ran. The second and 
  32. 99, third lines assign those values to the 
  33. 102, variables. And then I make a test to see if 
  34. 106, one of the Option buttons has been 
  35. 108, selected and its Value property been set to 
  36. 110, True. If this is the case, I use an 
  37. 113, advanced operator and the two variables to 
  38. 115, create a result, and I assign that to the 
  39. 118, Caption property of the Label1 object. 
  40. 124, You can use this program logic to manage 
  41. 125, any of the calculations you make in 
  42. 127, Visual Basic. And you'll learn more about 
  43. 130, the If...Then decision structure in 
  44. 131, Chapter 5.
  45. 133, END